package com.xinghou.platform.lucene.main.bean;

import com.xinghou.platform.model.main.User;
import com.xinghou.platform.util.StringUtils;
import org.apache.solr.client.solrj.beans.Field;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by qingshengzheng on 16/4/26.
 */
public class UserSolr {
    @Field
    public Integer userid;
    @Field
    public Integer usertype;
    @Field
    public String anothername;
    @Field
    public Integer storeid;
    @Field
    public String hascard;
    @Field
    public String storename;
    @Field
    public Integer sex;
    @Field
    public Integer regstatus;
    @Field
    public String nickname;
    @Field
    public String signature;
    @Field
    public String birthday;
    @Field
    public Long updatetime;
    @Field
    public Long createtime;
    public String provincename;
    public String cityname;
    @Field
    public String provincecode;
    @Field
    public String citycode;
    @Field
    public String position;
    @Field
    public List<String> taste= new  ArrayList<String>() ;

    public Integer getAgeyear() {
        return ageyear;
    }

    public void setAgeyear(Integer ageyear) {
        this.ageyear = ageyear;
    }

    @Field
    public Integer  ageyear;


    @Field
    public String ad_code;
    @Field
    public String ad_code_province;
    @Field
    public String ad_code_city;
    @Field
    public String ad_code_region;
    public static UserSolr fromUser(User user)
    {
        UserSolr userSolr=new UserSolr();
        userSolr.userid=user.getUserid();
        userSolr.usertype=user.getUsertype()==null?null:Integer.parseInt(user.getUsertype().toString());
        userSolr.storeid=user.getStoreid();
        userSolr.sex=user.getSex()==null?null:Integer.parseInt(user.getSex().toString());
        userSolr.nickname=user.getNickname();
        if(!StringUtils.isEmpty(user.getAgeyear()))
        userSolr.ageyear=Integer.parseInt(user.getAgeyear());
        userSolr.updatetime=user.getUpdatetime();
        userSolr.createtime=user.getCreatetime();
        userSolr.citycode=user.getCitycode();
        userSolr.hascard=user.getHascard();

        userSolr.citycode=user.getCitycode();
        userSolr.hascard=user.getHascard();

        userSolr.ad_code=user.getAd_code();
        userSolr.ad_code_province=user.getAd_code_province();
        userSolr.ad_code_city=user.getAd_code_city();
        userSolr.ad_code_region=user.getAd_code_region();

        if(!StringUtils.isEmpty(user.getTaste()))
        {
            String[] tastes=user.getTaste().split("-");
            for(int i=0;i<tastes.length;i++)
            {
                userSolr.taste.add(tastes[i]);
            }
        }
        if(user.getLatitude()!=null)
        userSolr.position=user.getLatitude()+","+user.getLongitude();

        return userSolr;
    }

    public  User toUser()
    {
        User user=new User();
        user.setUserid(userid);
        user.setUsertype(usertype==null?null:Short.parseShort(usertype.toString()));
        user.setStoreid(storeid);
        user.setSex(sex==null?null:Short.parseShort(sex.toString()));
        user.setRegstatus(regstatus==null?null:Short.parseShort(regstatus.toString()));
        user.setNickname(nickname);
        user.setSignature(signature);
        user.setUpdatetime(updatetime);
        user.setCreatetime(createtime);
        user.setCitycode(citycode);
        if(!StringUtils.isEmpty(position)) {
            System.out.print("position========="+position);
            try {
                user.setLatitude(Double.parseDouble(position.split(",")[0]));
                user.setLongitude(Double.parseDouble(position.split(",")[1]));
            }catch (Exception e)
            {
                e.printStackTrace();

            }
        }
        return user;
    }




}
